#ifndef __RENDERER_H__
#define __RENDERER_H__

#include <Windows.h>

#include "Defines.h"

#define DEG_TO_RAD(x) ((x) * (3.141592654f)/180)

struct IDirect3DDevice9;
struct D3DXMATRIX;
struct D3DXVECTOR3;

namespace MegaEngine
{
	class Camera;

	template <class VertexType, unsigned int FVF>
	class VertexBuffer;

	struct ENGINE_API ColorVertex{
		float x, y, z;
		//float rhw;
		DWORD color; 
	};

	enum ENGINE_API DrawPrimitives {
		PointList = 0,
		LineList,
		LineStrip,
		TriangleList,
		TriangleStrip,
		TriangleFan
	};

	enum ENGINE_API Matrix_Mode
	{
		World = 0,
		View,
		Projection
	};

	class ENGINE_API Renderer
	{
	public:
		Renderer(HWND window);
		~Renderer();
		bool Init();
		bool BeginScene();
		bool EndScene();
		bool Draw(DrawPrimitives primitive, int vertexCount, ColorVertex* vertexs);

		void loadIdentity();
		void setMatrixMode(Matrix_Mode mode);
		void setViewportPosition();
		void setViewportPosition(Camera* camera);
		void Translate(float x, float y, float z);
		void Scale(float x, float y, float z);
		void RotateX(float angle);
		void RotateY(float angle);
		void RotateZ(float angle);
	private:
		D3DXMATRIX* getTransform();

		HWND winHandle;
		IDirect3DDevice9* graphCardHandle;
		void * colVertexBuffer;

		Matrix_Mode matrixMode;
		
		D3DXMATRIX * projectionMatrix;
		
		D3DXMATRIX * viewerMatrix;
		D3DXVECTOR3 * viewerPos;
		D3DXVECTOR3 * viewerUp;

		//Camera * mainCamera;
		friend Camera;
	};
}

#endif //__RENDERER_H__